# Copyright 2024 Iguazio
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Update artifact table

Revision ID: b31651280cce
Revises: 6925effc8fb1
Create Date: 2025-05-20 16:32:16.453997

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "b31651280cce"
down_revision = "6925effc8fb1"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("artifacts_v2", sa.Column("parent_id", sa.Integer(), nullable=True))
    op.create_index(
        op.f("ix_artifacts_v2_parent_id"), "artifacts_v2", ["parent_id"], unique=False
    )
    op.create_foreign_key(
        "parent_id_key",
        "artifacts_v2",
        "artifacts_v2",
        ["parent_id"],
        ["id"],
        ondelete="SET NULL",
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("parent_id_key", "artifacts_v2", type_="foreignkey")
    op.drop_index(op.f("ix_artifacts_v2_parent_id"), table_name="artifacts_v2")
    op.drop_column("artifacts_v2", "parent_id")
    # ### end Alembic commands ###
